/*
 * TMap Designer - A Thematic Map design software
 * Copyright (C) 2006 World Health Organization
 * http://www.who.int
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package who.tmap.imp.shapefile.shapes.impl;

import who.tmap.common.TMapException;
import who.tmap.common.TMapFactory;
import who.tmap.imp.ImportAdapterException;
import who.tmap.imp.shapefile.shapes.Shape;
import who.tmap.imp.shapefile.shapes.Shapes;

/**
 * A Factory dedicated to shape file objects
 * @author stl
 *
 */
public class ShapeFactory implements TMapFactory, Shapes {

    private static ShapeFactory instance =null;
    
    /**
     * Private constructor because it is a singleton
     *
     */
    private ShapeFactory() {
    }
    
    /**
     * Lazy instanciation of the factory instance
     * @return
     */
    public static synchronized ShapeFactory getInstance() {
        if ( instance == null ) {
            instance =new ShapeFactory();
        }
        
        return instance;
    }
    
    /**
     * Instanciates shape file objects
     * @param import adapter type
     * @return
     * @throws ImportAdapterException
     * @throws TMapException
     */
    public Shape getShape( int shapeType ) throws TMapException {
        Shape shape =null;
        
        switch( shapeType ) {
        	case NULL_SHAPE:
        	    shape =new NullShapeImpl();
        	    break;
        	    
        	case POINT:
        	    shape =new PointImpl();
        	    break;
        	    
            case POLYLINE:
                shape =new PolyLineImpl();
                break;
                
            case POLYGON:
                shape =new PolygonImpl();
                break;

            case MULTI_POINT:
                shape =new MultiPointImpl();
                break;
               
            case POINT_Z:
                shape =new PointZImpl();
                break;
                
            case POLYLINE_Z:
                shape =new PolyLineZImpl();
                break;
                
            case POLYGON_Z:
                shape =new PolygonZImpl();
                break;
                
            case MULTI_POINT_Z:
                shape =new MultiPointZImpl();
                break;
                
            case POINT_M:
                shape =new PointMImpl();
                break;
                
            case POLYLINE_M:
                shape =new PolyLineMImpl();
                break;

            case POLYGON_M:
                shape =new PolygonMImpl();
                break;
                
            case MULTI_POINT_M:
                shape =new MultiPointMImpl();
                break;
                
            case MULTI_PATCH:
                shape =new MultiPatchImpl();
                break;
                
            // Not really a shapes per se
            // but we put it here for convenience
                
            case BOX:
                shape =new BoxImpl();
                break;
                
            case RANGE:
                shape =new RangeImpl();
                break;                
        	    
        	default:
        	    throw new TMapException( "Invalid shape type: [" + shapeType + "]" );
        }
        
        return shape;
    }

}
